//
//  UIColor+XTExtension.m
//  XTMuteOpen
//
//  Created by bushAK on 2024/1/22.
//

#import "UIColor+XTExtension.h"

@implementation UIColor (XTExtension)
+(UIColor *)hex:(NSString *)hexStr;{
    // 去除可能包含的空格和换行符
    NSString *cleanedString = [hexStr stringByReplacingOccurrencesOfString:@" " withString:@""];
    cleanedString = [cleanedString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    
    // 移除可能包含的 '#' 符号
    if ([cleanedString hasPrefix:@"#"]) {
        cleanedString = [cleanedString substringFromIndex:1];
    }
    
    // 将十六进制字符串转换为整数值
    NSScanner *scanner = [NSScanner scannerWithString:cleanedString];
    unsigned int hexValue;
    [scanner scanHexInt:&hexValue];
    
    // 分别提取 RGB 分量
    CGFloat red = ((hexValue & 0xFF0000) >> 16) / 255.0;
    CGFloat green = ((hexValue & 0x00FF00) >> 8) / 255.0;
    CGFloat blue = (hexValue & 0x0000FF) / 255.0;
    
    // 创建 UIColor 对象
    UIColor *color = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
    
    return color;

}

+(UIColor *)getBaseColor;{
    return  [self hex:@"#191E6B"];
}
@end
